package com.ecric.http.webView;

import android.app.Activity;
import android.view.KeyEvent;
import android.webkit.WebView;

import com.ecric.http.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

/**
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> Eric
 * <h3>Date</h3> 2017/9/21 14:10
 * <h3>Copyright</h3> Copyright (c)2017 Shenzhen TLKY  Co., Ltd. Inc. All rights reserved.
 */
@EActivity(R.layout.activity_webview_test)
public class WebViewTestActivity extends Activity{
    @ViewById(R.id.webview)
    WebView webView;
    @AfterViews
    void initData(){
        //设置WebView属性，能够执行JavaScript脚本
        webView.getSettings().setJavaScriptEnabled(true);
        //加载URL内容
        webView.loadUrl("http://www.baidu.com");
        //设置web视图客户端
        webView.setWebViewClient(new MyWebViewClient());
    }
    //设置回退
    @Override
    public boolean onKeyDown(int keyCode,KeyEvent event) {
        if((keyCode==KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode,event);
    }
}
